package com.houdoudou.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.houdoudou.bean.DatabaseAndTable;

public class DatabaseAndTableDao {
      	 	 
	   Connection conn=null;
	   
	public DatabaseAndTableDao(Connection conn) {
		super();
		this.conn = conn;
	}

	public  boolean createDatabase(){	
		boolean result=false;
		  PreparedStatement pstm=null; 
		   Statement  stm=null;
		   ResultSet rs=null; 	
		 String sql= DatabaseAndTable.sqlCreateDatabase;
	        try {
				pstm=conn.prepareStatement(sql);
				pstm.executeUpdate();
				result=true;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				result=false;
				e.printStackTrace();
			}finally{
				ConnFactory.closeStatment(pstm, pstm, rs);
			}
		
		return result;
	}

	public  boolean createTable(String sql){	
		boolean result=false;
		  PreparedStatement pstm=null; 
		   Statement  stm=null;
		   ResultSet rs=null; 	
	        try {
				pstm=conn.prepareStatement(sql);
				pstm.executeUpdate();
				result=true;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				result=false;
				e.printStackTrace();
			}finally{
				ConnFactory.closeStatment(pstm, pstm, rs);
			}
		
		return result;
	}
	
}
